import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue'),
      children: [{
        path: 'team',
        component: () => import('../views/Team.vue'),
      },
      {
        path: 'history',
        component: () => import('../views/History.vue')
      }]
    },
    {
      path: '/user/:id',
      name: 'user',
      component: () => import('../views/User.vue'),

    },
    // {
    //   path: '/parent',
    //   name: 'user',
    //   component: () => import('../views/parent.vue'),
    //   children: [{
    //     path: "child1",
    //     component: () => import(`../views/child1.vue`)
    //   },
    //   {
    //     path: "child2",
    //     component: () => import(`../views/child2.vue`)
    //   }

    //   ]
    // },
    {
      path: '/parent/:id',
      name: 'user',
      component: () => import('../views/parent.vue'),
      children: [{
        path: "child1",
        component: () => import(`../views/child1.vue`)
      },
      {
        path: "child2",
        component: () => import(`../views/child2.vue`)
      }

      ]
    },
  ],
})
router.beforeEach((to, from, next) => {
  if (to.path === '/about') {
    const isConfirmed = confirm('确定要访问关于页面吗？')
    isConfirmed ? next() : next(false)
  } else {
    next()
  }
})
export default router
